package com.ruoyi.web.controller.bookkeeping;

import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.bookkeeping.domain.param.PageQueryParam;
import com.ruoyi.bookkeeping.domain.param.UpdateBookFriendsParam;
import com.ruoyi.bookkeeping.domain.vo.BookFriendsVo;
import com.ruoyi.bookkeeping.domain.vo.MsgResult;
import com.ruoyi.bookkeeping.domain.vo.TableDataInfoVo;
import com.ruoyi.bookkeeping.util.GetPageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bookkeeping.service.IBookFriendsService;

/**
 * 好友Controller
 * 
 * @author ruoyi
 * @date 2023-02-24
 */
@RestController
@RequestMapping("/bookkeeping/friends")
@Api(tags = "好友模块")
public class BookFriendsController extends BaseController
{
    @Autowired
    private IBookFriendsService bookFriendsService;

    @GetMapping("/list")
    @ApiOperation("查询好友列表")
    public TableDataInfoVo<List<BookFriendsVo>> list(PageQueryParam pageQuery)
    {
        Page page = GetPageUtil.getPages(pageQuery.getPageNum(),pageQuery.getPageSize(),bookFriendsService.selectBookFriendsList(getUserId()));
        return getDataTable(page.getRecords(),page.getTotal());
    }

    @GetMapping("/findFriends")
    @ApiOperation("查询好友")
    public MsgResult<List<BookFriendsVo>> findFriends(String username, String nickName)
    {
        List<BookFriendsVo> friends = bookFriendsService.findFriends(username,nickName,getUserId());
        return success(friends);
    }

    @Log(title = "好友", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改好友备注")
    public MsgResult edit(@RequestBody UpdateBookFriendsParam bookFriends)
    {
        return toAjax(bookFriendsService.updateBookFriends(bookFriends,getUserId()));
    }

    @Log(title = "好友", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    @ApiOperation("删除好友")
    public MsgResult remove(@PathVariable Long id)
    {
        return toAjax(bookFriendsService.deleteBookFriendsById(id,getUserId()));
    }
}
